/*
package com.huqing.icu.rentplatform.service.impl;

import com.huqing.icu.constants.KafkaTopicConstants;
import com.huqing.icu.enums.report.ReportApproveStatusEnum;
import com.huqing.icu.enums.report.ReportRecordBusTypeEnum;
import com.huqing.icu.enums.report.ReportRecordSourceType;
import com.huqing.icu.exceptions.BusinessException;
import com.huqing.icu.model.report.ReportRecord;
import com.huqing.icu.protocol.SystemResponseCode;
import com.huqing.icu.rentplatform.inout.in.report.ReportRecordApproveReq;
import com.huqing.icu.rentplatform.mapper.ReportRecordMapper;
import com.huqing.icu.rentplatform.service.ReportRecordApproveService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;

*/
/**
 * 举报记录审核实现类
 *
 * @author huqing
 * @date 2024-11-23 12:36
 *//*

@Service
public class ReportRecordApproveServiceImpl implements ReportRecordApproveService {

    private static final Logger logger = LoggerFactory.getLogger(ReportRecordApproveService.class);

    @Resource
    private ReportRecordMapper reportRecordMapper;
    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;

    */
/**
     * 审核举报记录
     *
     * @param approveReq
     * @param authUserId
     * @return
     *//*

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer approveReport(ReportRecordApproveReq approveReq, Long authUserId) {
        ReportRecord reportRecord = reportRecordMapper.selectById(approveReq.getId());
        if (reportRecord == null) {
            throw new BusinessException(SystemResponseCode.PARAM_VALUE_ILLEGAL.getCode(), "无法找到要审核的记录");
        }
        //1、检查参数，审核状态是123，如果前端传的参数是456，则校验住
        Integer approveStatus = approveReq.getApproveStatus();
        if (approveStatus == null || ReportApproveStatusEnum.of(approveStatus) == null) {
            throw new BusinessException(SystemResponseCode.PARAM_VALUE_ILLEGAL.getCode(), "请求的审核状态不合法");
        }
        //1.2 如果不是待审核的状态，说明已经审核过
        if (!ReportApproveStatusEnum.PROCESSING.getCode().equals(approveStatus)) {
            throw new BusinessException(SystemResponseCode.INTERNAL_ERROR.getCode(), "已经审核过，不能重复审核");
        }

        //2 将审核记录保存到数据库
        //如果是审核不通过，会保存不通过的原因
        reportRecord.setReason(approveReq.getReason());
        reportRecord.setApproveStatus(approveStatus);
        reportRecord.setOperatorId(authUserId);
        reportRecord.setApproveTime(new Timestamp(System.currentTimeMillis()));
        reportRecordMapper.updateById(reportRecord);

        //2.2 如果审核通过
        if (ReportApproveStatusEnum.PASS.getCode().equals(approveStatus)) {

            //2.3 如果是举报评论，则删除评论，如果是举报业务（比如帖子），则删除业务本身。 都是使用MQ进行删除
            deleteTargetBusByMQ(reportRecord.getBusId(), reportRecord.getBusType(), reportRecord.getSourceType(), reportRecord.getSourceId());
        } else if (ReportApproveStatusEnum.NOT_PASS.getCode().equals(approveStatus)) {

            //2.4 如果审核不通过，由于前面已经保存了审核不通过的原因，所以这里暂时不需要处理，如果想发短信，可以通过MQ发短信
        }
        return 1;
    }


    @Override
    public String testKafka() {
        kafkaTemplate.send(KafkaTopicConstants.DELETE_COMMENT, "123");
        return "发送kafka消息成功";
    }

    */
/**
     * 使用MQ删除业务本身
     *
     * @param busId
     * @param busType
     * @return
     *//*

    private Integer deleteTargetBusByMQ(Long busId, Integer busType, Integer sourceType, Long sourceId) {

        Boolean isComment = ReportRecordSourceType.COMMENT.getCode().equals(sourceType);
        if (isComment) {
            //2.3 使用MQ删除评论
            kafkaTemplate.send(KafkaTopicConstants.DELETE_COMMENT, sourceId);
            return 1;
        }

        //如果是房源，则删除房源
        if (ReportRecordBusTypeEnum.HOUSE.getCode().equals(busType)) {
            kafkaTemplate.send(KafkaTopicConstants.DELETE_HOUSE, busId);
            return 1;
        }

        //如果是帖子，则删除帖子
        if (ReportRecordBusTypeEnum.COMMUNITY_POST.getCode().equals(busType)) {
            kafkaTemplate.send(KafkaTopicConstants.DELETE_COMMUNITY_POST, busId);
            return 1;
        }
        return 1;
    }
}
*/
